﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【角色与部门】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto角色与部门
    /// </summary>
    public abstract class AutoRoleDepartmentMapping : BaseMapping<RoleDepartment, RoleDepartmentModel, RoleDepartmentFilterModel>
    {
        public AutoRoleDepartmentMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override RoleDepartmentModel Entity2Model(RoleDepartment entity)
        {
            RoleDepartmentModel model = new RoleDepartmentModel();

            model.RoleDepartmentID = entity.RoleDepartmentID;
            model.GroupInfoID = entity.GroupInfoID;
            model.RoleID = entity.RoleID;
            model.DepartmentID = entity.DepartmentID;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override RoleDepartment Model2Entity(RoleDepartmentModel model)
        {
            RoleDepartment entity = new RoleDepartment();

            entity.RoleDepartmentID = model.RoleDepartmentID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.RoleID = model.RoleID;
            entity.DepartmentID = model.DepartmentID;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<RoleDepartment> FilterModel2Where(RoleDepartmentFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._RoleDepartmentID.HasValue)
            {
                where = where.And(x => x.RoleDepartmentID == filterModel._RoleDepartmentID.Value);
            }
            if (filterModel._RoleDepartmentIDs.IsNotEmpty() && filterModel._RoleDepartmentIDs.Count > 0)
            {
                where = where.And(x => filterModel._RoleDepartmentIDs.Contains(x.RoleDepartmentID));
            }
            if (filterModel._NotRoleDepartmentIDs.IsNotEmpty() && filterModel._NotRoleDepartmentIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotRoleDepartmentIDs.Contains(x.RoleDepartmentID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //角色
            if (filterModel._RoleID.HasValue)
            {
                where = where.And(x => x.RoleID == filterModel._RoleID.Value);
            }
            if (filterModel._RoleIDs.IsNotEmpty() && filterModel._RoleIDs.Count > 0)
            {
                where = where.And(x => filterModel._RoleIDs.Contains(x.RoleID));
            }
            if (filterModel._NotRoleIDs.IsNotEmpty() && filterModel._NotRoleIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotRoleIDs.Contains(x.RoleID));
            }

            //部门
            if (filterModel._DepartmentID.HasValue)
            {
                where = where.And(x => x.DepartmentID == filterModel._DepartmentID.Value);
            }
            if (filterModel._DepartmentIDs.IsNotEmpty() && filterModel._DepartmentIDs.Count > 0)
            {
                where = where.And(x => filterModel._DepartmentIDs.Contains(x.DepartmentID));
            }
            if (filterModel._NotDepartmentIDs.IsNotEmpty() && filterModel._NotDepartmentIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotDepartmentIDs.Contains(x.DepartmentID));
            }

            return where;
        }
        #endregion
    }
}

